layui.use(['jquery','layer', 'form'], function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
        $ = layui.jquery;

    //登录按钮
    	form.on("submit(login)",function(data){
    		$.post("/main/login/index",data.field,function(data) {
            	if(data.success){
            		window.location.href = "/main/index";
            	}else{
            		layer.msg(data.message);
            	}
            });
            
        })
        
	$(document.documentElement).on("keyup", function(event) {
		var keyCode = event.keyCode;
		var paramstr=$("#loginForm").serialize();
		if (keyCode === 13) { 
			$.post("/main/login/index",paramstr,function(data) {
            	if(data.success){
            		window.location.href = "/main/index";
            	}else{
            		layer.msg(data.message);
            	}
            });
		}
	});
    //表单输入效果
    $(".loginBody .input-item").click(function(e){
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function(){
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function(){
        $(this).parent().removeClass("layui-input-focus");
        if($(this).val() != ''){
            $(this).parent().addClass("layui-input-active");
        }else{
            $(this).parent().removeClass("layui-input-active");
        }
    })
    
})
